package edu.bu.met683.TravelDroid;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

/**
 * THIS CLASS IS NOT CURRENTLY IN USE: SUPERCEEDED BY THE POIDETAILACTIVITY This
 * activity is used only to handle the request to play an audio file.
 */
public class POIAudioActivity extends Activity {

	private static String CLASS_TAG = POIAudioActivity.class.getSimpleName();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onStart() {
		super.onStart();
		Log.v(CLASS_TAG, "onStart() Called");

		// Retrieve the Query String
		if ((getIntent().getData() != null)
				&& (getIntent().getData().getEncodedQuery() != null)) {
			String queryString = getIntent().getData().getEncodedQuery();
			Log.v(CLASS_TAG, "onStart(): retrieved query string = "
					+ queryString);

			String audioFileName = queryString.substring(9);
			Log.v(CLASS_TAG, "audioFileName = " + audioFileName);

			int audioResource = getResources().getIdentifier(
					"edu.bu.met683.TravelDroid:raw/" + audioFileName, null,
					null);

			MediaUtilities.playMediaFromRaw(this, audioResource);
		} else {
			Log.e(CLASS_TAG, "onStart(): No Query String Provided");
		}

		// Get a reference to the close button and handle button click
		this.setContentView(R.layout.poiaudiolayout);
		Button closeButton = (Button) findViewById(R.id.close_audio_button);
		closeButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}
}
